/**
 * @Author: 焦质晔
 * @Date: 2019/6/20
 * @Last Modified by: mikey.zhaopeng
 * @Last Modified time: 2020-01-06 19:57:09
 */
import axios from '@/api/fetch';
import * as types from './types';
import SERVER from '@/api/server';
// 查询品牌下拉框
export const getBrandList = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/brandsqueryall`, { params });
// 查询车系下拉框
export const getSeriesList = (brandsid, params) => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/brandsdict/${brandsid}/seriessdict`, { brandsid: brandsid, params: params });
// 条件查询车系
export const getSeries = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/seriess`, { params });
// 查询单个车系
export const getSeriesById = id => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/seriess/${id}`, { id: Number(id) });
// 新增一个车系
export const addSeries = params => axios.post(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/seriess`, params);
// 修改车辆销售指导价
export const editCarPrice = params => axios.put(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/car/editCarPrice`, params);
// 导出车系
export const getSeriesExport = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/seriess/export/excel`, { params });
// 修改一个车系
export const updateSeries = (params, id) => axios.put(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/seriess/${id}`, { params });


//  查询车型下拉框
export const getModelList = (brandsid, seriessid, params) => {
  const url = `${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/brandsdict/${brandsid}/seriessdict/${seriessid}/modelsdict`
  return axios.get(url, {
    seriessid: seriessid,
    brandsid: brandsid,
    params: params
  })
}
//  查询配置下拉框
export const getPackageList = (brandsid, seriessid, modelId, params) => {
  const url = `${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/brandsdict/${brandsid}/seriessdict/${seriessid}/modelsdict/${modelId}/packagesdict`
  return axios.get(url, {
    seriessid: seriessid,
    brandsid: brandsid,
    modelId: modelId,
    params: params
  })
}
// 查询外饰色下拉框
export const getWcolorList = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/colors/colorinfo/exterior`, { params });
// 查询内饰色下拉框
export const getIcolorList = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/colors/colorinfo/Interior`, { params });
//  条件查询车系
// export const getCar = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/productInfo`, { params });
export const getCar = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/productInfo/V2`, { params });
//  新增一个车辆主数据
export const addCar = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/productInfo`, { params });
// 导出车系
export const getCarExport = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/productInfo/export/excel2`, { params });
// 修改一个车辆主数据
export const updateCar = (params, id) => axios.put(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/productInfo/${id}`, { params });
// 修改一个车辆主数据
export const importCar = (params, id) => axios.put(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/productInfo/import`, { params });

// 导出最新
export const getExcelList = (params = {}) => {
  for (const key in params) {
    if (!params[key]) {
      params[key] = ''
    }
  }
  const url = `${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/productInfo/export/excel`
    + '?limit=100000&pageNum=' + params.pageNum +
    '&productCode=' + params.productCode +
    '&productName=' + params.productName +
    '&brandName=' + params.brandName +
    '&seriesName=' + params.seriesName +
    '&modelName=' + params.modelName +
    '&packageName=' + params.packageName +
    '&productStatus=' + params.productStatus +
    '&dataSources=' + params.dataSources +
    '&interiorColor=' + params.interiorColor +
    '&colorId=' + params.colorId +
    '&isValid=' + params.isValid
  return axios({
    url,
    method: 'get',
    responseType: 'blob'
  });
}
export const getExcelListV2 = (params = {}) => {
  for (const key in params) {
    if (!params[key]) {
      params[key] = ''
    }
  }
  const url = `${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/productInfo/export/excelV2`
    + '?limit=100000&pageNum=' + params.pageNum +
    '&productCode=' + params.productCode +
    '&productName=' + params.productName +
    '&brandName=' + params.brandName +
    '&seriesName=' + params.seriesName +
    '&modelName=' + params.modelName +
    '&packageName=' + params.packageName +
    '&optionName=' + params.optionName +
    '&productStatus=' + params.productStatus +
    '&dataSources=' + params.dataSources +
    '&interiorColor=' + params.interiorColor +
    '&colorId=' + params.colorId +
    '&isValid=' + params.isValid
  return axios({
    url,
    method: 'get',
    responseType: 'blob'
  });
}
//导出车辆主数据 wst ,之前搜索字段的条件是写死的，改为动态参数
export const getExcelListV3 = params => {
  return axios({
      url: `${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/productInfo/export/excelV2`,
      method: 'get',
      params: params,
      responseType: 'blob'
  });
};

//  条件查询车系
// export const getCarOEM = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/dcs/vehicleProduct/productInfo/list`, { params });
export const getCarOEM = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/dcs/vehicleProduct/productInfo/listV2`, { params });
//  新增一个车辆主数据
// export const addCarOEM = params => axios.post(`${SERVER.DMSCLOUD_SYSBASEDATA}/dcs/vehicleProduct/productInfo/saveOrUpdate`, params);
export const addCarOEM = params => axios.post(`${SERVER.DMSCLOUD_SYSBASEDATA}/dcs/vehicleProduct/productInfo/saveOrUpdateV2`, params);
//  整车分类定义分页查询
export const qrySortDefinitionPage = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/basedata/qrySortDefinitionPage`, { params });



// 查询品牌下拉框
export const getBrandListOEM = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/dcs/vehicleProduct/queryBrandDictAll`, { params });
// 查询车系下拉框
export const getSeriesListOEM = (brandsid, params) => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/dcs/vehicleProduct/brandsdict/${brandsid}/seriessdictAll`, { brandsid: brandsid, params: params });
//  查询车型下拉框
export const getModelListOEM = (brandsid, seriessid, params) => axios.get(`${SERVER.BASEDATA}/dcs/vehicleProduct/brandsdict/${brandsid}/seriessdictAll/${seriessid}/modelsdictAll`, { params });
//  查询配置下拉框
export const getPackageListOEM = (brandsid, seriessid, modelId, params) => {
  const url = `${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/brandsdict/${brandsid}/seriessdict/${seriessid}/modelsdict/${modelId}/packagesdict`
  return axios.get(url, {
    seriessid: seriessid,
    brandsid: brandsid,
    modelId: modelId,
    params: params
  })
}

//查询车系品牌新增下拉框(店端)
export const getBrandListDictOEM = (params) => axios.get(`${SERVER.BASEDATA}/dcs/vehicleProduct/queryBrandDictOwner`, { params });
//新增编辑界面本店面车系下拉框(店端)
export const getSeriesListDictOEM = (brandsId,params) => axios.get(`${SERVER.BASEDATA}/dcs/vehicleProduct/brandsdict/${brandsId}/queryBrandDictOwner`, { params });
//  查询车型新增下拉框(店端)
export const getModelListDictOEM = (brandsid, seriessid, params) => axios.get(`${SERVER.BASEDATA}/dcs/vehicleProduct/brandsdict/${brandsid}/seriessdictAll/${seriessid}/queryBrandDictOwner`, { params });
//  查询配置下新增下拉框(店端)
export const getPackageListDictOEM = (brandsid, seriessid, modelsid, params) => axios.get(`${SERVER.BASEDATA}/dcs/vehicleProduct/brandsdict/${brandsid}/seriessdict/${seriessid}/modelsdict/${modelsid}/packagesdict`, { params });
// 查询选装
export const getOptionListDictOEM = packageId => axios.get(`${SERVER.BASEDATA}/option/vsOption/getOptionByPackageId/${packageId}`);

